define(['text!./Home.html', 'css!./Home.css', 'swipe'], function(html) {
	avalon.templateCache['Home'] = html;
	var vm = avalon.define({
		$id: "Home",
		setup: function() {
			Router.go('/setup/setup');
		},
		result: function() {
			var token=JSON.parse(getstorage('token'));
//			alert(token);
			if(token){
				var user=JSON.parse(getstorage('user'));
//				alert(user.phone);
				if(user.phone){
					Router.go('/result/result');
				}else{
					Router.go('/selfInfo/selfInfo');
				}
			}else{
				initiateUI()
			}
		},
		message: function() {
			Router.go('/message/message');
		},
		addFamily: function() {
//			bindCode();
			Router.go('/addInfo/addInfo');
		},
		basic: function(id) {
			Router.go('/basic/basic', JSON.stringify(id));
		},
		user:JSON.parse(getstorage('user')),
		swipe: function() {
			var swiper = new Swiper('.swiper-container', {
				pagination: '.swiper-pagination',
				paginationClickable: true,
				spaceBetween: 0,
				centeredSlides: true,
				autoplay: 2500,
				autoplayDisableOnInteraction: false
			});

		},
		list: [],
		leftList: [],
		rightList: [],
		getData: function() {
			var user = JSON.parse(getstorage('user'))
//			alert(user.idu);
			httpPost('user/getFamily', {
				userId:user.idu
			}).done(function(data) {
				if("200" == data.code) {
					vm.list = data.items;
					vm.leftList = [];
					vm.rightList = [];
					for(var i = 0; i < vm.list.length; i++) {
						if(i % 2 == 0) {
							vm.leftList.push(vm.list[i]);
						} else {
							vm.rightList.push(vm.list[i]);
						}
					}
				} else {
					msgbox('提示', data.msg);
				}
			});
		},
//		getDate:function(){
//			var	user={
//		        id: 56,
//		        userName: "天明",
//		        password: null,
//		        birthday: "2003-12-01",
//		        sex: "1",
//		        phone: '12312312312',
//		        tel: "12345671234567",
//		        emPhone: "13227237096",
//		        userId: null,
//		        height: null,
//		        weight: null,
//		        unionid: null,
//		        refreshToken: null,
//		        deviceId: "190e35f7e04a17f0243",
//		        deviceinfo: "0",
//		        status: "1",
//		        createTime: "2016-12-23",
//		        updateTime: null,
//		        headphoto: null,
//		        realName: null,
//		        sbp: "111",
//		        dbp: "71",
//		        pulseRate: "51",
//		        measureTime: "2016-12-19",
//		        idu: "153482475979903"
//		    }
//			setstorage('user',user);
//		},
		init: function() {
//			vm.getDate();
			vm.swipe();
			vm.getData();
		}
	});
});